package sz.szsmk.citizencard.mvp.presenter;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.response.NoticeDetailRes;
import sz.szsmk.citizencard.mvp.contract.INoticeDetailContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.model.network.bean.request.NoticeDetailReq;
import sz.szsmk.citizencard.util.ACache;

import javax.inject.Inject;

/**
 * Copyright (c)2018
 * 欣网互联网络科技有限公司
 * author: zdh
 * created on: 2018/8/14 11:45
 * description:
 */
public class NoticeDetailPresenter extends IBasePresenter
implements INoticeDetailContact.INoticeDetailPresenter<INoticeDetailContact.INoticeDetailView>{

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public NoticeDetailPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    @Override
    public void getNoticeDetail(String detailId) {
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        NoticeDetailReq noticeDetailReq = new NoticeDetailReq();
        noticeDetailReq.setAccess_token(access_token);
        noticeDetailReq.setDetailId(detailId);
        noticeDetailReq.setDevice_id("52");
        noticeDetailReq.setSign("25");
        mNetworkDateSource.getNoticeDetail(noticeDetailReq, new SubscribeResult<NoticeDetailRes>() {
            @Override
            protected void onOk(NoticeDetailRes response) {
                ((INoticeDetailContact.INoticeDetailView) mView).getNoticeDetailSuccess(response);
            }

            @Override
            protected void onNext(NoticeDetailRes response) {
                super.onNext(response);
                ((INoticeDetailContact.INoticeDetailView) mView).getNoticeDetailError(response.getMessage());
            }

            @Override
            protected void onFailure(NoticeDetailRes response) {
                super.onFailure(response);
                ((INoticeDetailContact.INoticeDetailView) mView).getNoticeDetailError(response.getMessage());
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

}
